function setDefaultMain() {
   var current_point = parseInt($('.container .content .main-item .item-lists').css('margin-left'));
   if (current_point == 0) {
      $('#main_prev').hide();
      $('#control_prev').hide();
   } else if (current_point == -3495) {
      $('#main_next').hide();
      $('#control_next').hide();
   }
   
}
function setDefaultMainImage() {
   $('.main-item .item-image img').attr('width', '216px').attr('height', '140px');
}
function setDefaultSubmain() {
   $('#submain_prev').hide();
   $('#control_prev').hide();
}
function setDefaultSubmainImage() {
   $('.submain-item .item-image img').attr('width', '216px').attr('height', '140px');
}
function loadContent(act, type, order) {
   mainStatus = 1;
   keyStatus = 0;
   $('.loading').show();
   $.post("/ajax_main", function(data){
      $('#content').html(data);
      setDefaultMainImage();
      $('#menu_home').addClass('menu-hover').addClass('menu-select');
      if (act == 'main' && type == 2) {
         main_item_hover('main_item_list_' + order);
         $('.container .content .main-item .item-lists').css('margin-left', (-1165 * (Math.ceil(order / 5) - 1)) + 'px');
      } else if (act != 'init') {hilight_play_hover();}
      setDefaultMain();
      $('.loading').hide();
      keyStatus = 1;
   });
}
function call_return(path) {
   if (path != '') {window.location.href=path;}
}
function call_submain(type, page, order, act) {
   keyStatus = 0;
   mainStatus = 0;
   $('.loading').show();

   if (act == 'prev') {
      $('#submain_prev img').attr('src', assets_url+'images/xl/btn_main_prev_down.png');
   } else if (act == 'next') {
      $('#submain_next img').attr('src', assets_url+'images/xl/btn_main_next_down.png');
   }
   $.post("/ajax_sub_main/"+type+"/"+page, function(data){
      $('#content').html(data);
      setDefaultSubmainImage();
      if (page > 1) {
         $('#submain_prev').show();
         $('#control_prev').show();
      } else {
         $('#submain_prev').hide();
         $('#control_prev').hide();
      }
      if (page < 50) {
         $('#submain_next').show();
         $('#control_next').show();
      } else {
         $('#submain_next').hide();
         $('#control_next').hide();
      }
      clear_all_menu_select();
      if (type == 1) {$('#menu_mv').addClass('menu-select');} else if (type == 6) {$('#menu_interview').addClass('menu-select');} else if (type == 4) {$('#menu_concert').addClass('menu-select');} else if (type == 3) {$('#menu_behind').addClass('menu-select');}
      if (order != '') {
         submainPointId = order;
      }
      submain_item_hover('submain_item_list_' + submainPointId);
      $('.loading').hide();
      keyStatus = 1;
   });
}
function slide_main(act) {
   keyStatus = 0;
   var target_point = 0;
   var pixel_width = 1165;
   var current_point = parseInt($('.container .content .main-item .item-lists').css('margin-left'));
   if (act == 'prev') {
      $('#main_prev img').attr('src', assets_url+'images/xl/btn_main_prev_down.png');
      target_point = current_point + pixel_width;
      if (target_point > 0) {
         target_point = 0;
      }
   } else if (act == 'next') {
      $('#main_next img').attr('src', assets_url+'images/xl/btn_main_next_down.png');
      target_point = current_point - pixel_width;
      if (target_point < -3495) {
         target_point = -3495;
      }
   }
   $('.container .content .main-item .item-lists').animate({'margin-left': target_point+'px'}, '1000', function() {
      if (target_point == 0) {
         $('#main_prev').hide();
         $('#control_prev').hide();
      } else {
         $('#main_prev').show();
         $('#control_prev').show();
      }
      if (target_point == -3495) {
         $('#main_next').hide();
         $('#control_next').hide();
      } else {
         $('#main_next').show();
         $('#control_next').show();
      }
      if (act == 'prev') {
         $('#main_prev img').attr('src', assets_url+'images/xl/btn_main_prev.png');
      } else if (act == 'next') {
         $('#main_next img').attr('src', assets_url+'images/xl/btn_main_next.png');
      }
      keyStatus = 1;
   });
}
function menu_select(obj, submain_id) {
   if (obj == 'menu_home') {loadContent();} else {loadSubMain(submain_id);}
   clear_all_menu_select();
   $('#'+obj).addClass('menu-select');
}
$('#menu_home').live('click', function(event) {menu_select($(this).attr('id'));});
function loadSubMain(obj, point_id) {
   keyStatus = 0;
   mainStatus = 0;
   $('.loading').show();
   if (point_id == null) {
      point_id = 1;
   }
   $.post("/ajax_sub_main/" + obj, function(data){
      $('#content').html(data);
      setDefaultSubmain();
      setDefaultSubmainImage();
      submain_item_hover('submain_item_list_' + point_id);
      $('.loading').hide();
      keyStatus = 1;
   });
}
$('#menu_mv').live('click', function(event) {
   menu_select($(this).attr('id'), 1);
});
$('#menu_interview').live('click', function(event) {
   menu_select($(this).attr('id'), 6);
});
$('#menu_concert').live('click', function(event) {
   menu_select($(this).attr('id'), 4);
});
$('#menu_behind').live('click', function(event) {
   menu_select($(this).attr('id'), 3);
});
function main_item_hover(obj) {
   clear_all_main_hover();
   $('#'+obj).addClass('item-hover');
   $('#'+obj).find('.item-image img').attr('width', '228px').attr('height', '148px');
   currentFocus = obj;
}

$('.main-item .item-lists .item-list').live('mouseenter', function(event) {main_item_hover($(this).attr('id'));});
function submain_item_hover(obj) {
   clear_all_main_hover();
   $('#'+obj).addClass('item-hover');
   $('#'+obj).find('.item-image img').attr('width', '228px').attr('height', '148px');
   currentFocus = obj;
   submainPointId = parseInt(currentFocus.substring(18));
}
$('.submain-item .item-lists .item-list').live('mouseenter', function(event) {submain_item_hover($(this).attr('id'));});

$('#control_prev img').live('mouseenter', function(event) {
   $(this).attr('src', assets_url+'images/xl/btn_control_prev_hover.png');
});
$('#control_prev img').live('mouseout', function(event) {
   $(this).attr('src', assets_url+'images/xl/btn_control_prev.png');
});
$('#control_next img').live('mouseenter', function(event) {
   $(this).attr('src', assets_url+'images/xl/btn_control_next_hover.png');
});
$('#control_next img').live('mouseout', function(event) {
   $(this).attr('src', assets_url+'images/xl/btn_control_next.png');
});
$('#control_full img').live('mouseenter', function(event) {
   $(this).attr('src', assets_url+'images/xl/btn_control_full_hover.png');
});
$('#control_full img').live('mouseout', function(event) {
   $(this).attr('src', assets_url+'images/xl/btn_control_full.png');
});
$('#control_return img').live('mouseenter', function(event) {
   $(this).attr('src', assets_url+'images/xl/btn_control_back_hover.png');
});
$('#control_return img').live('mouseout', function(event) {
   $(this).attr('src', assets_url+'images/xl/btn_control_back.png');
});
$('#control_back img').live('mouseenter', function(event) {
   $(this).attr('src', assets_url+'images/xl/btn_control_back_hover.png');
});
$('#control_back img').live('mouseout', function(event) {
   $(this).attr('src', assets_url+'images/xl/btn_control_back.png');
});
$('#control_exit img').live('mouseenter', function(event) {
   $(this).attr('src', assets_url+'images/xl/btn_control_exit_hover.png');
});
$('#control_exit img').live('mouseout', function(event) {
   $(this).attr('src', assets_url+'images/xl/btn_control_exit.png');
});

function clear_all_menu_select() {
   $('.menu ul.menu li.main-menu').removeClass('menu-select');
}

function clear_all_main_hover() {
   $('.menu ul.menu li.main-menu').removeClass('menu-hover');
   $('#hilight_play img').attr('src', assets_url+'images/xl/btn_play.png');
   $('.main-item .item-list').removeClass('item-hover');
   setDefaultMainImage();
   $('.submain-item .item-list').removeClass('item-hover');
   setDefaultSubmainImage();
}

function menu_hover(obj) {
   clear_all_main_hover();
   $('#'+obj).addClass('menu-hover');
   currentFocus = obj;
}
$('#menu_home').live('mouseenter', function(event) {menu_hover('menu_home');});
$('#menu_mv').live('mouseenter', function(event) {menu_hover('menu_mv');});
$('#menu_concert').live('mouseenter', function(event) {menu_hover('menu_concert');});
$('#menu_interview').live('mouseenter', function(event) {menu_hover('menu_interview');});
$('#menu_behind').live('mouseenter', function(event) {menu_hover('menu_behind');});

function hilight_play_hover() {
   clear_all_main_hover();
   $('#hilight_play img').attr('src', assets_url+'images/xl/btn_play_hover.png');
   currentFocus = 'hilight_play';
}

$('#hilight_play img').live('mouseenter', function(event) {hilight_play_hover();});

$('#submain_prev img').live('mouseenter', function(event) {
   $(this).attr('src', assets_url+'images/xl/btn_main_prev_hover.png');
});
$('#submain_prev img').live('mouseout', function(event) {
   $(this).attr('src', assets_url+'images/xl/btn_main_prev.png');
});
$('#submain_prev img').live('mousedown', function(event) {
   $(this).attr('src', assets_url+'images/xl/btn_main_prev_down.png');
});

$('#submain_next img').live('mouseenter', function(event) {
   $(this).attr('src', assets_url+'images/xl/btn_main_next_hover.png');
});
$('#submain_next img').live('mouseout', function(event) {
   $(this).attr('src', assets_url+'images/xl/btn_main_next.png');
});
$('#submain_next img').live('mousedown', function(event) {
   $(this).attr('src', assets_url+'images/xl/btn_main_next_down.png');
});

function main_prev() {
   if (!keyStatus) {return;}
   if (currentFocus.substring(0, 15) == 'main_item_list_') {
      var point_id = parseInt(currentFocus.substring(15)) - 5;
      if (point_id <= 1) {
         point_id = 1;
      }
      main_item_hover('main_item_list_' + point_id);
   }
   slide_main('prev');
}

$('#main_prev img').live('mouseenter', function(event) {
   $(this).attr('src', assets_url+'images/xl/btn_main_prev_hover.png');
});
$('#main_prev img').live('mouseout', function(event) {
   $(this).attr('src', assets_url+'images/xl/btn_main_prev.png');
});

function main_next() {
   if (!keyStatus) {return;}
   if (currentFocus.substring(0, 15) == 'main_item_list_') {
      var point_id = parseInt(currentFocus.substring(15)) + 5;
      if (point_id >= 20) {
         point_id = 20;
      }
      main_item_hover('main_item_list_' + point_id);
   }
   slide_main('next');
}
$('#main_next img').live('mouseenter', function(event) {
   $(this).attr('src', assets_url+'images/xl/btn_main_next_hover.png');
});
$('#main_next img').live('mouseout', function(event) {
   $(this).attr('src', assets_url+'images/xl/btn_main_next.png');
});

$('#control_prev').live('click', function(event) {
   jQuery.globalEval($('#main_prev').attr('onclick'));
   jQuery.globalEval($('#submain_prev').attr('onclick'));
});
$('#control_next').live('click', function(event) {
   jQuery.globalEval($('#main_next').attr('onclick'));
   jQuery.globalEval($('#submain_next').attr('onclick'));
});
$('#control_exit').live('click', function(event) {window.NetCastExit();});
$('#control_back').live('click', function(event) {window.NetCastReturn(VK_BACK);});
$('#control_full').live('click', function(event) {executeAction('full');});